from django.db import models
from user.models import SysUser

# Create your models here.
#系统角色类
class SysRole(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=100, unique=True, verbose_name="角色名称")
    code = models.CharField(max_length=100, unique=True, verbose_name="角色权限")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="修改时间")
    remark = models.CharField(max_length=500, null=True, verbose_name="备注")
    
    
    def __str__(self):
        return self.role.name
    
    class Meta:
        db_table = "sys_role"
        
#系统用户角色关联类
class SysUserRole(models.Model):
    id = models.AutoField(primary_key=True)
    user = models.ForeignKey(SysUser, on_delete=models.CASCADE, verbose_name="用户")
    role = models.ForeignKey(SysRole, on_delete=models.CASCADE, verbose_name="角色")
    
    class Meta:
        db_table = "sys_user_role"
    